<template>
	<!-- 页面全局配置 -->
	<view class="pageconfig" :style="{'padding-top':StatusBar + 'px'}">
		<!--vuetop-->
		<text class="text1 text-lg text-bold "> 答题历史</text>
		<view class="flex2   response  flex  justify-start  " style="flex-direction: column;">

			<view class="flex3   response  flex  justify-around  "
				style="display: flex;flex-direction: column;background-color: #fff;padding: 10px;border-radius: 25px;"
				v-for="(item,index) in log_list">
				<view class="header" style="display: flex;flex-direction: column;justify-content: space-around;">
					<view class="title" style="font-size: 16px;font-weight: 600;">
						<text> {{item.quiz_id}}</text>
					</view>
					<view class="t" style="display: flex;flex-direction: row;justify-content: space-between;">
						<text style="font-size: 12px;font-weight: 600;color: red;">
							总分：{{item.subData.total_score}}</text>
						<text style="font-size: 12px;font-weight: 600;color: red;"> 得分：{{item.score}}</text>
					</view>
				</view>
				<view class="body" style="font-weight: 100;padding: 20px;">
					<view class="list" v-for="(item1,index1) in item.exerc_json" style="padding: 10px;">
						<view class="item">
							<view class="index">
								第{{item1.index}}题，我的选择：{{item1.select}},答案为：{{item1.correct}}
							</view>
							题目：{{item1.topic}}
						</view>
					</view>
				</view>
				<view class="footer">
					<text> 答题时间：{{timestampToDateString(item.complete_time)}}</text>
				</view>
			</view>

		</view>
	</view>
</template>


<script>
	import Vue from 'vue'
	const db = uniCloud.database()
	let abu_answer_log_db = db.collection('abu-answer-log');
	export default {
		data() {
			return {
				StatusBar: 0,
				log_list: []
			};
		},
		async onLoad() {
			uni.showLoading({
				title: '加载中',
				mask: false
			});
			const user_info = await uniCloud.getCurrentUserInfo();
			this.getsysinfo();
			const data = await abu_answer_log_db.where({
				member_id: user_info.uid
			}).get();
			this.log_list = data.result.data.map(item => {
				return {
					...item,
					exerc_json: JSON.parse(item.subData.exerc_json)
				}
			})
			console.log(this.log_list);
			uni.hideLoading()

		},
		methods: {
			timestampToDateString(timestamp) {
				var date = new Date(timestamp);
				// 使用 Date 对象的方法获取年、月、日等信息
				var year = date.getFullYear();
				var month = date.getMonth() + 1; // 月份是从 0 开始的，所以需要加 1
				var day = date.getDate();
				// 将其格式化为想要的字符串格式
				var dateString = (month < 10 ? '0' : '') + month + '-' + (day < 10 ? '0' : '') + day;
				return dateString;
			},

			//获取顶部状态栏的高度
			getsysinfo() {
				let that = this;
				uni.getSystemInfo({
					success: function(e) {
						that.StatusBar = e.statusBarHeight;
						// #ifdef H5
						that.StatusBar = 0;
						// #endif


					}
				})

			},

		}
	}
</script>

<style lang="less">
	.pageconfig {
		width: 100%;
		overflow: hidden;
		overflow-y: scroll;
		height: 100vh;
		background-color: #e6e6e6;
	}



	/**pagedomcss**/


	.text1 {
		margin-top: 40rpx;
		margin-bottom: 40rpx;
		margin-left: 40rpx;
	}

	.flex2 {
		width: 100%;
	}

	.flex3 {
		width: 100%;
		width: calc(100% - 80rpx);
		margin-top: 40rpx;
		margin-bottom: 40rpx;
		margin-left: 40rpx;
		margin-right: 40rpx;
	}

	.flex7 {
		width: 100%;
		width: calc(100% - 80rpx);
		margin-top: 40rpx;
		margin-bottom: 40rpx;
		margin-left: 40rpx;
		margin-right: 40rpx;
	}
</style>